home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / TIME_ZON / GENROUTI.C < prev    next >
Text File  |  1991-11-08  |  4KB  |  257 lines

  1. /* GenRoutines.c
  2.  * These routines are used variously by the different libraries.
  3.  */
  4.  
  5. #include "CNameList.h"
  6. #include <Global.h>
  7. #include <GenRoutines.h>
  8. #include <Packages.h>
  9. #include <math.h>
  10.  
  11.     /*
  12.      * This stuff is for my own access to SANE, and it's been around
  13.      * for awhile, so ignore it
  14.      */
  15.  
  16. #define FLOATDECIMAL 0
  17. #define FIXEDDECIMAL 1
  18.  
  19. typedef struct {
  20.     char style, unused;
  21.     short digits;
  22. } decform;
  23.  
  24. typedef struct {
  25.     char sgn, unused;
  26.     short exp;
  27.     unsigned char sig[22];
  28. } decimal;
  29.  
  30. decform gdecform;
  31.  
  32. decimal gdecimal;
  33.  
  34. #define odd(x)        ((x)%2 ? TRUE : FALSE)
  35.  
  36. /***********************************/
  37.  
  38.  
  39.     /*
  40.      * This will put a little black outline around the first item of the
  41.      * dialog box, which should be OK
  42.      */
  43.  
  44. pascal void
  45. outline_ok(dlg,which)
  46. DialogPtr dlg;
  47. short which;
  48. {
  49.     short type;
  50.     Handle item;
  51.     Rect box;
  52.     
  53.     GetDItem(dlg,1,&type,&item,&box);
  54.     PenSize(3,3);
  55.     InsetRect(&box,-4,-4);
  56.     FrameRoundRect(&box,18,18);
  57. }
  58.  
  59.  
  60.     /*
  61.      * This will install a procedure into a dialog as a certain item
  62.      * (For example the routine above)
  63.      */
  64.  
  65. void
  66. install_useritem(dlg,which,what)
  67. DialogPtr dlg;
  68. short which;
  69. ProcPtr what;
  70. {
  71.     short type;
  72.     Handle item;
  73.     Rect box;
  74.     
  75.     GetDItem(dlg,which,&type,&item,&box);
  76.     SetDItem(dlg,which,type,what,&box);
  77. }
  78.  
  79.  
  80.     /*
  81.      * My version of atof
  82.      */
  83.  
  84. double
  85. atofl(alpha)
  86. char *alpha;
  87. {
  88.     int index;
  89.     Boolean junk;
  90.     double dtemp;
  91.     
  92.     index = 0;
  93.     asm {
  94.             MOVE.L alpha,-(SP)
  95.             PEA    index
  96.             PEA gdecimal
  97.             PEA junk
  98.             MOVE.W    #4,-(SP)
  99.             DC.W 0xA9EE
  100.     }
  101.     asm {
  102.             PEA gdecimal
  103.             PEA dtemp
  104.             MOVE.W #0x9,-(SP)
  105.             DC.W 0xA9EB
  106.     }
  107.     return(dtemp);
  108. }
  109.  
  110.     /*
  111.      * My version of ftoa
  112.      */
  113.  
  114. char *
  115. ftoa(numbr, str, decpl, expon)    
  116. double numbr;
  117. char *str;
  118. short decpl, expon;
  119. {
  120.     Str255 junk;
  121.     
  122.     gdecform.style = FIXEDDECIMAL;
  123.     gdecform.digits = decpl;
  124.     asm {
  125.             PEA    gdecform
  126.             PEA numbr
  127.             PEA gdecimal
  128.             MOVE.W    #0xB,-(SP)
  129.             DC.W 0xA9EB
  130.     }
  131.     asm {
  132.             PEA gdecform
  133.             PEA gdecimal
  134.             PEA junk
  135.             MOVE.W    #3,-(SP)
  136.             DC.W 0xA9EE
  137.     }
  138.     strcpy(str,PtoCstr(&junk));
  139.     return(str);
  140. }
  141.  
  142.  
  143. void
  144. copy_rectangle(r1,r2)
  145. Rect *r1, *r2;
  146. {
  147.     BlockMove((Ptr) r1, (Ptr) r2,sizeof(Rect));
  148. }
  149.  
  150.  
  151.     /*
  152.      * The following routines are designed to handle input/output from
  153.      * editboxes in a dialog. They are not all used in Time Zone, but
  154.      * they can be handy.
  155.      */
  156.  
  157.  
  158. void
  159. set_text(thedlg,which,thetext)
  160. DialogPtr thedlg;
  161. short which;
  162. char *thetext;
  163. {
  164.     short thetype;
  165.     Handle theitem;
  166.     Rect thebox;
  167.     char ptext[256];
  168.     
  169.     strcpy(ptext,thetext);
  170.     GetDItem(thedlg,which,&thetype,&theitem,&thebox);
  171.     SetIText(theitem, (Str255 *) CtoPstr(ptext));
  172. }
  173.  
  174.  
  175. void
  176. get_text(thedlg,which,thetext)
  177. DialogPtr thedlg;
  178. short which;
  179. char *thetext;
  180. {
  181.     short thetype;
  182.     Handle theitem;
  183.     Rect thebox;
  184.     char mytext[256];
  185.     
  186.     GetDItem(thedlg,which,&thetype,&theitem,&thebox);
  187.     GetIText(theitem,(Str255 *) mytext);
  188.     while (mytext[mytext[0]] == ' ')
  189.         mytext[0]--;
  190.     strcpy(thetext,PtoCstr(mytext));
  191.     
  192. }
  193.  
  194.  
  195. double
  196. get_float(thedlg,which)
  197. DialogPtr thedlg;
  198. short which;
  199. {
  200.     short thetype;
  201.     Handle theitem;
  202.     Rect thebox;
  203.     char ptext[256];
  204.     double atofl();
  205.     
  206.     GetDItem(thedlg,which,&thetype,&theitem,&thebox);
  207.     GetIText(theitem,(Str255 *) ptext);
  208.     return(atofl(PtoCstr(ptext)));
  209. }
  210.  
  211.  
  212. void
  213. set_float(thedlg,which,theval,places)
  214. DialogPtr thedlg;
  215. short which;
  216. double theval;
  217. short places;
  218. {
  219.     short thetype;
  220.     Handle theitem;
  221.     Rect thebox;
  222.     char ctext[256];
  223.     
  224.     GetDItem(thedlg,which,&thetype,&theitem,&thebox);
  225.     SetIText(theitem,(Str255 *) CtoPstr(ftoa(theval,ctext,places,0)));
  226. }
  227.  
  228.  
  229. short
  230. get_radio(thedlg,which)
  231. DialogPtr thedlg;
  232. short which;
  233. {
  234.     short thetype;
  235.     Handle theitem;
  236.     Rect thebox;
  237.     
  238.     GetDItem(thedlg,which,&thetype,&theitem,&thebox);
  239.     return(GetCtlValue((ControlHandle) theitem));
  240. }
  241.  
  242.  
  243. void
  244. set_radio(thedlg,which,how)
  245. DialogPtr thedlg;
  246. short which, how;
  247. {
  248.     short thetype;
  249.     Handle theitem;
  250.     Rect thebox;
  251.     
  252.     GetDItem(thedlg,which,&thetype,&theitem,&thebox);
  253.     SetCtlValue((ControlHandle) theitem, Abs(how));
  254. }
  255.  
  256.  
  257.